package pl.lodz.p.browarex.mvc;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import pl.lodz.p.browarex.model.OrderProductInfo;
import pl.lodz.p.browarex.model.Product;
import pl.lodz.p.browarex.services.interfaces.IAnalysisTypeService;
import pl.lodz.p.browarex.services.interfaces.IProductService;
import pl.lodz.p.browarex.services.interfaces.IUserService;

@Controller
public class ProductController {

	@Inject
	IUserService userService;

	@Inject
	IAnalysisTypeService analysisTypeService;

	@Inject
	IProductService productService;

	@RequestMapping(value = "/product", method = RequestMethod.GET)
	public String showProduct(@RequestParam("id") String UID, Model model) {
		if (UID != null) {
			model.addAttribute("orderProductInfo", new OrderProductInfo());
			List<Product> products = new ArrayList<Product>();
			products.add(productService.loadByProductID(UID));
			model.addAttribute("productsList", products);
			return "index";
		}
		return "redirect:index";
	}
}
